package com.weex.app.extend;

import android.widget.Toast;

import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.bridge.JSCallback;
import com.taobao.weex.common.WXModule;

import java.util.HashMap;
import java.util.Map;

public class WXTestModule extends WXModule {

    /**
     * 自定义发送事件
     */
    @JSMethod
    public void getTestData(JSCallback callback) {
        Map<String,String> data = new HashMap<>();
        data.put("k1","Get This Android Event Success.");
        callback.invoke(data);//调用后销毁
//        callback.invokeAndKeepAlive(data);//调用后不销毁持续存在
    }

    @JSMethod
    public void showToast(String msg) {
        Toast.makeText(mWXSDKInstance.getContext(), msg, Toast.LENGTH_SHORT).show();
    }

    @JSMethod
    public void testGlobal() {
        Map<String,Object> map = new HashMap<>();
        map.put("key","value");
        mWXSDKInstance.fireGlobalEventCallback("geolocation",map);
    }
}
